package com.amos.base.base;

/**
 * @author Amos
 * @ClassName Result
 * @Description TODO
 * @Date 2018/12/22 23:22
 * @VERSION 1.0
 **/
public class Result {
    /**
     * 成功
     */
    public static final Integer SUCCESS = 0;
    /**
     * 验证失败
     */
    public static final Integer VALIDATEERROR = 1;
    /**
     * 程序异常
     */
    public static final Integer ERROR = -1;

    public static final String DEFAULT_SUCCESS_MSG = "ok";
    public static final String DEFAULT_ERROR_MSG = "系统异常";
    public static final String DEFAULT_VALIDATEERROR_MSG = "";

    private String msg;

    private Integer code;

    private Object data;

    public static class Builder {
        private String msg;

        private Integer code;

        private Object data;
        public Builder(Integer code){
            this.code = code;
        }

        public Builder msg(String msg){
            this.msg = msg;
            return this;
        }
        public Builder data(Object data){
            this.data = data;
            return this;
        }

        public Result builder(){
            return new Result(this);
        }
    }
    public Result(Builder builder){
        this.code = builder.code;
        this.msg = builder.msg;
        this.data = builder.data;
    }
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 处理结果是否正确
     * @param result
     * @return
     */
    public static boolean isSuccess(Result result){
        if (Result.SUCCESS.equals(result.getCode())){
            return true;
        }
        return false;
    }
}
